package com.baor.controller;

import com.baor.config.TokenService;
import com.baor.service.ExceptiongdService;
import com.baor.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/exceptiongd")
@Slf4j
public class ExceptiongdController {
    @Autowired
    private ExceptiongdService exceptiongdService;

    @Autowired
    private TokenService tokenService;
    /**
     * @param params
     * @return
     */
    @RequestMapping("/getList")
    public R getList(@RequestBody Map<String, Object> params) {
        log.info("开始查询设备工单列表");
        R r = exceptiongdService.getList(params);
        return R.ok(r);
    }
    /**
     * @param id
     * @return
     */
    @RequestMapping("/getOneList/{id}")
    public R getOneList(@PathVariable("id") Integer id) {
        log.info("开始查询设备工单详情");
        R r = exceptiongdService.getInfo(id);
        return R.ok(r);
    }


    /**
     * @param params
     * @return
     */

    @RequestMapping("/insert")
    public R insert(@RequestBody Map<String, Object> params,@RequestHeader(value = "token") String token) {
        log.info("开始添加设备工单");
        if (token == null) {
            return R.er("未登录或token不存在");
        }
        Integer userId = tokenService.getUserId(token);
        if (userId == null) {
            return R.er("token无效");
        }
        params.put("reportUserId", userId);
        System.out.println(params);
        R r = exceptiongdService.insert(params);
        return R.ok(r);
    }
}
